feat: leader election with kube api and send through k8s#271
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR implements leader election for the Mojave sequencer using Kubernetes to enable high availability through automated failover. The solution uses the kube-leader-election library with a 15-second TTL lease that is renewed every 3 seconds by the current leader.
Key changes:
- Added Kubernetes deployment manifests supporting 3-replica sequencer deployment with leader election
- Implemented leader election logic in
k8s_leader.rsthat coordinates task management based on leadership status - Added comprehensive documentation for local Minikube setup and testing
Reviewed Changes
Copilot reviewed 15 out of 16 changed files in this pull request and generated 19 comments.
Show a summary per file
| File | Description |
|---|---|
| k8s/setup.sh | Shell script to deploy sequencer resources to Kubernetes |
| k8s/ovh.setup.sh | OVH-specific deployment script with hardcoded kubeconfig path |
| k8s/service.sequencer.yaml | Service definition exposing HTTP and P2P ports |
| k8s/rbac.sequencer.yaml | RBAC configuration granting lease management permissions |
| k8s/pvc.yaml | Persistent volume configuration using hostPath (Minikube-specific) |
| k8s/ovh.pvc.yaml | OVH-specific PVC using Cinder storage |
| k8s/deploy.sequencer.yaml | Deployment with 3 replicas, environment variables, and volume mounts |
| docs/k8s.md | Comprehensive guide for Kubernetes deployment and failover testing |
| cmd/sequencer/src/main.rs | Refactored to detect K8s environment and delegate to leader election logic |
| cmd/sequencer/src/k8s_leader.rs | New module implementing Kubernetes leader election and task lifecycle management |
| cmd/sequencer/Cargo.toml | Added kube dependencies for K8s API interaction |
| Cargo.toml | Added workspace dependencies for k8s-openapi, kube, and kube-leader-election |
| crates/block-producer/src/block_producer.rs | Added error logging for block production failures |
| crates/batch-producer/Cargo.toml | Added mojave-utils dependency |
| justfile | Removed SKIP_BUILD environment variable check |
| Cargo.lock | Updated dependency versions and added K8s-related dependencies |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
561425b to
941f2cf
Compare
Signed-off-by: Sacha Froment <sfroment42@gmail.com>
Signed-off-by: Sacha Froment <sfroment42@gmail.com>
Signed-off-by: Sacha Froment <sfroment42@gmail.com>
Signed-off-by: Sacha Froment <sfroment42@gmail.com>
Signed-off-by: Sacha Froment <sfroment42@gmail.com>
Signed-off-by: Sacha Froment <sfroment42@gmail.com>
Signed-off-by: Sacha Froment <sfroment42@gmail.com>
a398ffd to
b4c895f
Compare
sfroment
approved these changes
Dec 3, 2025
* chore: add health check Signed-off-by: Sacha Froment <sfroment42@gmail.com> * refactor: change the way the main is started Signed-off-by: Sacha Froment <sfroment42@gmail.com> * chore: nitpick * mod: k8s yaml * chore: remove command in justfile * chore: fix just sequencer & node , fix kill process in start.sh * chore: rm * refactor: coordination k8s (#276) * refactor: coordination k8s Signed-off-by: Sacha Froment <sfroment42@gmail.com> * chore: save Signed-off-by: Sacha Froment <sfroment42@gmail.com> * chore: keep health alive Signed-off-by: Sacha Froment <sfroment42@gmail.com> * fix: start Signed-off-by: Sacha Froment <sfroment42@gmail.com> * Apply suggestion from @Copilot Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * chore: remove useless Signed-off-by: Sacha Froment <sfroment42@gmail.com> * chore: review comment Signed-off-by: Sacha Froment <sfroment42@gmail.com> * chore: add back save on shutdown Signed-off-by: Sacha Froment <sfroment42@gmail.com> --------- Signed-off-by: Sacha Froment <sfroment42@gmail.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update justfile Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update cmd/sequencer/src/main.rs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update cmd/sequencer/src/cli.rs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update cmd/node/src/cli.rs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update cmd/sequencer/src/cli.rs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update justfile Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * chore: fix 1st call Signed-off-by: Sacha Froment <sfroment42@gmail.com> * Refactor: Use idiomatic assert! in CLI tests (#277) * Initial plan * Replace if-panic patterns with assert! in CLI tests Co-authored-by: sfroment <7238385+sfroment@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: sfroment <7238385+sfroment@users.noreply.github.com> * Fix missing assert in CLI test for command parsing (#278) * Initial plan * Fix matches! macro usage in sequencer CLI tests Added assert! around matches! calls in parse_stop_and_get_pub_key test to properly verify command types instead of just evaluating the boolean. Co-authored-by: sfroment <7238385+sfroment@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: sfroment <7238385+sfroment@users.noreply.github.com> --------- Signed-off-by: Sacha Froment <sfroment42@gmail.com> Co-authored-by: Giwook-Han <hkw00011@gmail.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com> Co-authored-by: sfroment <7238385+sfroment@users.noreply.github.com>
Signed-off-by: Sacha Froment <sfroment42@gmail.com>
Signed-off-by: Sacha Froment <sfroment42@gmail.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 32 out of 33 changed files in this pull request and generated 14 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Signed-off-by: Sacha Froment <sfroment42@gmail.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
8 tasks
Contributor
Contributor
8 tasks
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
4 tasks
Contributor
Contributor
5 tasks
* Initial plan * Fix StatefulSet name references in k8s documentation Co-authored-by: sfroment <7238385+sfroment@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: sfroment <7238385+sfroment@users.noreply.github.com>
…name (#282) * Initial plan * Fix documentation: update references from deploy.sequencer.yaml to stateful.sequencer.yaml Co-authored-by: sfroment <7238385+sfroment@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: sfroment <7238385+sfroment@users.noreply.github.com>
* Initial plan * Fix all references from deploy.sequencer.yaml to stateful.sequencer.yaml Co-authored-by: sfroment <7238385+sfroment@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: sfroment <7238385+sfroment@users.noreply.github.com>
* Initial plan * Call shutdown() on error paths to ensure consistent cleanup Co-authored-by: sfroment <7238385+sfroment@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: sfroment <7238385+sfroment@users.noreply.github.com>
Signed-off-by: Sacha Froment <sfroment42@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why is this change necessary?
Add sequencer failover process by using k8s.
Description
Add k8s lease logic (leader election logic) so that make multiple sequencer run for HA.
the lease has 15 secs of TTL and leader will renew it's lease every 3 secs.
Closes #262
Type of change
Checklist